<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\AppToken;
use Validator;

class SessionController extends Controller
{
    //
    public function create (Request $request) {

        $validator = Validator::make($request->all(), array(
            'userId' => 'bail|required|max:255',
            'value'  => 'bail|required|max:255'
        ));

        if ($validator->fails()) {
            echo json_encode(['status' => 0, 'errmsg' => $validator->errors(), 'data' => []]);
            return ;
        }

        $token = new AppToken();
        $sessionId = $token->Create($request->userId, $request->value, $vcode=null);

        echo json_encode(['status' => 200, 'errmsg' => '', 'data' => ["sessionId" => $sessionId]]);
    }
}
